欢迎来到四川自考网,今天是2020年8月21日

自考资讯热线:028-65656189

距离自考还有28

当前位置:首页 > 电脑认证 > 水平考试 >

2008年程序员考试模拟试卷——下午题

发布时间:2008-04-11 14:29:26

(考试时间 14:00~16:30 共150分钟)

  本试卷共8道题,考生需解答5道题,其中试题1~试题3是必答题,试题4和试题5两题任选1道题,试题6至试题8三题任选1道解答。对于任选题,如果解答的试题数超过1道,则题号小的1道题解答有效。每题15分,满分75分。

  试题一(15分,每空3分)

  阅读以下说明和流程图,将应填入__(n)__处的字句写在答题纸的对应栏内。

  [说明]

  已知头指针分别为La和Lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示。

  试题二(15分,每空3分)

  阅读以下函数说明和C语言函数,将应填入___(n)___处的字句写在答题纸的对应栏内。

  [程序2.1说明]

  已知一个排好序的数组,现输入一个数,要求按原来的顺序规律,将它插入到数组中。

  [程序2.1]

  #include

  #define N 100

  void main()

  {

  float a[N=1],x;

  int i,p;

  printf("输入已经排好序的数列:");

  for( i=0; i

  scanf(%f",&a[i]);

  printf("输入要插入的数:");

  scanf("%f",&x);

  for( i=0,p=N; i

  if(x

  {

  ___(1)___

  break;

  }

  for( i=N-1; i>=p; i-- )

  ___(2)___

  ___(3)___

  for( i=0; i<=N; i++ )

  printf("%f\t",a[i]);

  }

  [程序2.2说明]

  本程序用变量count统计文件中字符的个数。

  [程序2.2]

  #include

  #include

  void main()

  {

  FILE *fp;

  long count=0;

  if( (fp=fopen("letter.txt","r") ) == NULL )

  {

  printf("can not open file\n");

  exit(0);

  }

  while( !feof(fp) )

  {

  ___(4)___

  count++;

  }

  printf("count=%d\n",count);

  ___(5)___

  }

  试题三(15分,每空3分)

  阅读以下说明和C语言程序,将应填入___(n)___处的字句写在答题纸的对应栏内。

  [说明]

  Fibonacci数列A={11,2,3,5,8,…}有如下性质:

  a0=a1=1

  ai=ai-1+ai-2 i>1

  对于给定的n,另外有一个由n个元素组成的数列xn,该数列中各元素的值为:

  xi=ai/ai+1 i=0,1,…,n

  现要求对xn中的元素按升序进行排序,然后以分数形式输出排序后的xn。例如n=5时,排序前的xn={1/1,1/2,2/3,3/5,5/8},排序后的xn={1/2,3/5,5/8,2/3,1/1}。程序中函数make()首先生成排序前的xn,然后调用函数sort()进行排序,最后输出所求结果。

  [程序]

  #include

  #include

  #include

  struct fact

  {

  long m,n;

  };

  void sort(int n,struct fact *p)

  {

  int a;

  long s,t,u,v;

  struct fact *q,*end;

  for(end=p+(n-1),a=1;a;end--)

  for(a=0,q=p;q

  {

  s=q->m;

  t=q->n;

  u=(q+1)->m;

  v=(q+1)->n;

  if(___(1)___)

  {

  q->m=u;

___(2)___

  ___(3)___

  (q+1)->n=t;

  a=1;

  }

  }

  }

  void make(int n)

  {

  int i;

  long a,b,c;

  struct fact *x,*y;

  x=(struct fact *)malloc(sizeof(struct fact)*n);

  x->m=1;

  x->n=1;

  for( a=1,b=1,i=2;i<=n;i++)

  {

  ___(4)___

  a=b;

  b=c;

  (x+(i-1))->m=a;

  (x+(i-1))->n=b;

  }

  ___(5)___

  printf("x%d={%1d/%1d",n,x->m,x->n);

  for(y=x+1;y

  printf(",%1d/%1d",y->m,y->n);

  printf("}\n");

  free(x);

  }

  void main()

  {

  int n;

  printf("input n:");

  scanf("%d",&n);

  make(n);

  }

  试题四(15分,每空3分)(欢迎访问软件考试网www.hbsoft.net)

  阅读以下说明和C语言程序,将应填入___(n)___处的字句写在答题纸的对应栏内。

  [说明]

  本程序对某电码文(原文)进行加密形成密码文,其加密算法如下

  假定原文为C1,C2,C3,…,Cn加密后形成的密文为S1,S2,S3,…,Sn,首先读入正整数key(key>1)作为加密钥匙,并将密文字符位置按顺时针方向连成一个环,如下图所示:

  加密时从 S1 位置起顺时针计数,当数到第 key 个字符位置时,将原文中的字符放入该密文字符位置中,同时从环中除去该字符位置;接着从环中下一个字符位置起继续计数,当再次数到第 key 个字符位置时,将原文中字符 C2 放入其中,并从环中除去该字符位置;依次类推,直至 n 个原文字符全部放入密文环中。由此产生的 S1S2...Sn 即为原文的密文。

  例如,当 Key=3 时,原文:this is a decoding system 的密文为:

  aotgnhedi ys d imietsnc ss

  当Key=4时,该原文的密文为:

  ssdtyd htegiasiscnm e ion

#include

  #include

  typedef struct node

  { char ch;

  struct node *forward; /* Link to next node. */

  struct node *backward;/* Link to previous node.*/

  } CODE;

  int strlen(char *s)

  { int len = 0;

  while (*s++ != '\0' )

  len++;

  return( len );

  }

  char *decode(char *old,int key)

  { char *New; int length,count,i;

  CODE *loop,*p;

  length=strlen(old);

  loop=(CODE *) malloc( length*sizeof(CODE) );

  for ( i = 1;i

  { loop[i].forward = &loop[i+1];

  ___(1)___

  }

  loop[0].backward = &loop[length-1];

  loop[0].forward = &loop[1];

  loop[length-1].forward = loop;

  ___(2)___

  for ( p = loop,i = 0;i

  { for ( count = 1;count

  p= p->forward ;

  ___(3)___

  p->backward->forward = p->forward ;

  p->forward->backward = p->backward ;

  ___(4)___

  }

  New = ( char *)malloc( ( length+1 ) *sizeof(char) );

  for ( i=0;i

  ___(5)___

  New[length]='\0';

  return (New);

  }

  void main()

  { char old[256];

int key , num=0;

  printf("\nPlease input the telegraph: \n");

  while ( num<255 && ( old[num++] = getchar()) != '\n' );

  old [ (num==255)?num:num-1] = '\0';

  do

  { printf( "\nPlease input Key ( Key>1 ):" );

  scanf("%d",&key);

  } while ( key<=1 );

  printf( "\nThe decode of telegraph:'%s' is:\n'%s'\n",old,decode( old,key ) );

  }

  试题五(15分,每空3分)

  阅读以下说明及Visual Basic 程序代码,将应填入___(n)___处的字句写在答题纸的对应栏内。

  [说明]

  本程序实现如下功能:首先,单击“生成”按钮,生成一个由10个随机大写字母组成的字符串,并在文本框中显示。然后,单击“排序”按钮,将此随机字符串中的各个字母按递增顺序添加到列表框中。

  程序运行界面如下:

  [程序]

  As String

  Private Sub get_Click()

  Dim i As Integer

  Randomize

  For i = 1 To 10

  str1 = Trim(str1) & Chr(Int( ___(1)___ ))

  Next

  Text1.Text = str1

  End Sub

  Private Sub sort_Click()

  Dim i As Integer

  Dim j As Integer

  For i = 1 To 26

  j = ___(2)___

  Do While j > 0

  ___(3)___

  j = j - 1

  Loop

  Next

  End Sub

  Private Function search(str1 As String, str2 As String) As Integer

  Dim int1 As Integer, int2 As Integer

  int1 = 1

  Do

  int1 = ___(4)___

  If int1 = 0 Then Exit Do

  int2 = int2 + 1

  int1 = int1 + 1

  Loop

  search = ___(5)___

  End Function (

试题六(15分,每空3分)

  阅读以下说明和C++程序,将应填入___(n)___处的字句写在答题纸的对应栏内。


  [说明]

  字符串在程序设计中扮演着重要角色。现需要设计字符串基类string,包含设置字符串、返回字符串长度及内容等功能。另有一个具有编辑功能的串类edit_string,派生于string,在其中设置一个光标,使其能支持在光标处的插入、删除操作。

  [程序]

  #include

  #include

  #include

  class string

  {

  int length;

  char *data;

  public:

  int get_length() { return length; }

  char *get_data() { return data; }

  ~string() { delete data; }

  int set_data( int in_length, char *in_data);

  int set_data( char *data );

  void print() { cout<

  };

  class edit_string : public string

  {

  int cursor;

  public:

  int get_cursor() { return cursor; }

  void move_cursor( int dis ) { cursor=dis; }

  int add_data(string *new_data);

  void delete_data( int num );

  };

  int string::set_data( int in_length, char *in_data )

  {

  length=in_length;

  if(!data)

  delete data;

  ___(1)___

  strcpy(data,in_data);

  return length;

  }

  int string::set_data( char *in_data )

{

  ___(2)___

  if(!data)

  delete data;

  ___(1)___

  strcpy(data,in_data);

  return length;

  }

  int edit_string::add_data( string *new_data )

  {

  int n,k,m;

  char *cp,*pt;

  n=new_data->get_length();

  pt=new_data->get_data();

  cp=this->get_data();

  m=this->get_length();

  char *news = new char[n+m+1];

  for( int i=0; i

  news[i]=cp[i];

  k=i;

  for( int j=0; j

  news[i]=pt[j];

  cursor=i;

  for( j=k; j

  ___(3)___

  news[i]='\0';

  ___(4)___

  delete news;

  return cursor;

  }

  void edit_string::delete_data( int num )

  {

  int m;

  char *cp;

  cp=this->get_data();

  m=this->get_length();

  for( int i=cursor; i

  ___(5)___

  cp[i]='\0';

  }

  试题七(15分,每空3分)(

  阅读以下说明及Visual Basic 程序代码,将应填入___(n)___处的字句写在答题纸的对应栏内。

  [说明]

  设窗体上有两个文本框和一个按钮,在第一个文本框text1中输入一个全部由“0”和“1”组成的字符串,单击按钮,在第二个文本框text2中显示出给定字符串中连续的0和连续的1中连续字符数目的最大值。如果输入的字符串中有不是“0”和“1”的字符,使用消息框显示错误信息。

  运行界面如下:

 

  [程序]

  Private Sub Command1_Click()

  Dim strSource As String

  Dim str1 As String

  Dim result As Integer

  Dim int1 As Integer, num As Integer

  strSource = Text1.Text

  If Len(strSource) = 0 Then

MsgBox "请在文本框中输入由0和1组成的字符串"

  Exit Sub

  End If

  For int1 = 1 To Len(strSource)

  ___(1)___

  If str1 <> "1" And str1 <> "0" Then

  MsgBox "不能输入非0或非1的字符"

  Exit Sub

  End If

  Next

  str1 = ___(2)____

  num = 1

  For int1 = 2 To Len(strSource)

  If str1 = Mid(strSource, int1, 1) Then

  ___(3)___

  Else

  If result < num Then

  result = num

  End If

  str1 = Mid(strSource, int1, 1)

  ___(4)___

  End If

  Next

  If result < num Then

  result = num

  End If

  ___(5)___

  End Sub

  试题八(15分,每空3分)

  阅读以下说明、Java代码将应填入___(n)___处的字句写在答题纸的对应栏内。

  [说明]

  IC卡和200卡都是从电话卡派生。下面程序将电话卡定义为抽象类。其中balance为双精度变量,代表电话卡中的余额;cardNumber是长整型,代表电话卡的卡号;password是整型变量,代表电话卡的密码;connectNumber是字符串变量,代表电话卡的接入号码;connected是布尔变量,代表电话是否接通。

  performDial()实现各种电话接通后的扣除费用的操作。其中200卡每次通话扣除0.5元的通话费用和附加费用;IC卡每次通话扣除0.9元的通话费。TimeLeft()方法用于测试电话卡余额还可以拨打电话的次数。performConnection()用于电话接入操作,如果卡号和密码正确,则接通,否则,接不通。

  [程序]

  abstract class PhoneCard

  {

  double balace;

  ___(1)___ performDial();

  double getBalance()

  { return balance; }

  double TimeLeft()

  {

  double current=balance;

  int times=0;

  do

{

  ___(2)___

  times++;

  }while(balance>=0);

  balance=current;

  return times-1;

  }

  }

  abstract class Number_PhoneCard extends PhoneCard

  {

  long cardNumber;

  int password;

  String connectNumber;

  Boolean connected;

  Boolean performConnection( long cn, int pw )

  {

  if( cn==cardNumber && ___(3)___ )

  {

  connected=true;

  return true;

  }

  else return false;

  }

  }

  class IC_Card ___(4)___

  {

  boolean performDial()

  {

  if(balance>0.9)

  {

  balance-=0.9;

  return true;

  }

  else return false;

  }

  }

  class D200_Card ___(4)___

  {

  static double additoryFee;

  static{ additoryFee=0.1; }

  boolean performDial()

  {

  if(balance>(0.5+additoryFee))

  {

  ___(5)___

  return true;

  }

  else return false;

  }

  }

在线咨询
考试报名
官方微信
联系电话
028-65656189
返回顶部